package cm.tl.pms.controller;

import cm.tl.pms.common.entity.ResultMsg;
import cm.tl.pms.entity.vo.req.ProjectAddReq;
import cm.tl.pms.entity.vo.req.ProjectQueryReq;
import cm.tl.pms.entity.vo.resp.ProjectResp;
import cm.tl.pms.service.ProjectService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/project")
@Api("项目管理")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @ApiOperation("获取项目列表")
    @PostMapping("list")
    public ResultMsg<Page<ProjectResp>> list(@RequestBody ProjectQueryReq req) {
        return ResultMsg.successfulResult(projectService.page(req));
    }

    @ApiOperation("添加项目")
    @PostMapping("add")
    public ResultMsg<Boolean> add(@RequestBody @Valid ProjectAddReq req) {
        return ResultMsg.result(projectService.addProject(req));
    }

    @ApiOperation("更新项目")
    @PostMapping("update")
    public ResultMsg<Boolean> update(@RequestBody ProjectAddReq req) {
        return ResultMsg.result(projectService.updateProject(req));
    }

    @ApiOperation("项目详情")
    @GetMapping("getById")
    public ResultMsg<ProjectResp> getById(@RequestParam Long id) {
        return ResultMsg.successfulResult(projectService.getProject(id));
    }


}
